package com.ffmpeg.util.infra.handle.file;

import java.io.File;

import com.ffmpeg.util.infra.constant.DealWhenExistEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author :wm
 * @description : 文件存在时删除
 */
@Component
public class DeleteWhenExistHandle implements IDealWhenExistHandle {
    private final static Logger logger = LoggerFactory.getLogger(DeleteWhenExistHandle.class);

    @Override
    public String executeFileWhenExist(String filePath) {
        File file = new File(filePath);
        if (file.exists() && file.delete()) {
            logger.info("file {} delete success", filePath);
        }
        return filePath;
    }

    @Override
    public DealWhenExistEnum getType() {
        return DealWhenExistEnum.DELETE;
    }
}
